﻿#include "FITKRadiossCase.h"
#include "FITKRadiossMeshModel.h"
#include "FITKRadiossNodesParts.h"
#include "FITKPropAbstract.hpp"
#include "FITKNonLinerCurve.h"
#include "FITKRadiossSolution.h"
#include "FITKAbstractInteraction.h"
#include "FITK_Interface/FITKInterfacePhysics/FITKAbstractSection.h"
#include "FITK_Interface/FITKInterfacePhysics/FITKAbstractMaterial.h"

namespace Radioss
{
    FITKRadiossCase::FITKRadiossCase()
        : Core::FITKAbstractNDataObject()
    {
        _defaultPropValueManager = new FITKRadiossPropValueManager();
        _defaultInteractionManager = new FITKRadiossInteractionDefaultManager();
        _sectionManager = new Interface::FITKAbstractSectionManager();
        _materialManager = new Interface::FITKMaterialManager();
        _meshModel = new FITKRadiossMeshModel();
        _nonLinerCurveManager = new FITKNonLinerCurveManager();
        _solutionManager = new FITKRadiossSolutionManager();
        FITKRadiossSolution* solution = new FITKRadiossSolution;
        solution->setDataObjectName("Solution-1");
        _solutionManager->appendDataObj(solution);
 
    }
    FITKRadiossCase::~FITKRadiossCase()
    {
        if (_defaultPropValueManager) { delete _defaultPropValueManager; _defaultPropValueManager = nullptr; }
        if (_sectionManager) { delete _sectionManager; _sectionManager = nullptr; }
        if (_materialManager) { delete _materialManager; _materialManager = nullptr; }
        if (_meshModel) { delete _meshModel; _meshModel = nullptr; }
        if (_nonLinerCurveManager) { delete _nonLinerCurveManager; _nonLinerCurveManager = nullptr; }
        if (_solutionManager) { delete _solutionManager; _solutionManager = nullptr; }
    }
    Interface::FITKAbstractSectionManager* FITKRadiossCase::getSectionManager() const
    {
        return _sectionManager;
    }
    Interface::FITKMaterialManager* FITKRadiossCase::getMaterialManager() const
    {
        return _materialManager;
    }

    FITKRadiossMeshModel *FITKRadiossCase::getMeshModel() const
    {
        return _meshModel;
    }

    FITKRadiossBCSManager *FITKRadiossCase::getBCSManager() 
    {
        FITKRadiossSolution* sol = getCurrentSolution();
        if(sol)
            return sol->getBCSManager();
        return nullptr;
    }

    FITKNonLinerCurveManager *FITKRadiossCase::getNonLinerCurveManager() const
    {
        return _nonLinerCurveManager;
    }

    FITKRadiossPropValueManager *FITKRadiossCase::getDefaultPropValueManager() const
    {
        return _defaultPropValueManager;
    }

    FITKRadiossInteractionDefaultManager * FITKRadiossCase::getDefaultInteractionManager() const
    {
        return _defaultInteractionManager;
    }

    FITKInitialFieldManager *FITKRadiossCase::getInitialFieldManager()
    {
        FITKRadiossSolution* sol = getCurrentSolution();
        if(sol)
            return sol->getInitialFieldManager();
        return nullptr;
    }

    FITKRadiossRWallManager *FITKRadiossCase::getRWallManager()
    {
        FITKRadiossSolution* sol = getCurrentSolution();
        if(sol)
            return sol->getRWallManager();
        return nullptr;
    }

    FITKGravityManager *FITKRadiossCase::getGravityManager()
    {
        FITKRadiossSolution* sol = getCurrentSolution();
        if(sol)
            return sol->getGravityManager();
        return nullptr;
    }

    FITKInteractionManager *FITKRadiossCase::getInteractionManager()
    {
        FITKRadiossSolution* sol = getCurrentSolution();
        if(sol)
            return sol->getInteractionManager();
        return nullptr;
    }

    FITKRadiossSolverSettings * FITKRadiossCase::getSolverSettings()
    {
        FITKRadiossSolution* sol = getCurrentSolution();
        if(sol)
            return sol->getSolverSettings();
        return nullptr;
    }

    FITKRadiossResultRequest * FITKRadiossCase::getResultRequest()
    {
        FITKRadiossSolution* sol = getCurrentSolution();
        if(sol)
            return sol->getResultRequest();
        return nullptr;
    }

    FITKRadiossSolutionManager *FITKRadiossCase::getSolutionManager() const
    {
        return _solutionManager;
    }
    FITKRadiossSolution* FITKRadiossCase::getCurrentSolution()
    {
        if(_solutionManager)
        {
            return _solutionManager->getCurrentSolution();
        }
        return nullptr;
    }

} // namespace Radioss
